The SysInfo control helps Visual Basic programmers create applications that are compliant with the Windows logo program. One of the prerequisites for such applications is the ability to react to systemwide events, such as when the screen resolution changes or when a plug-and-play device is connected to or disconnected from the system.
The SysInfo control is embedded in the SysInfo.ocx file, which must be distributed with any application that uses this control.
The SysInfo control is pretty easy to use: It doesn't expose any design-time properties or support any methods. You use a SysInfo control by querying its run time-only properties and writing code for its events. The properties of a SysInfo control can be subdivided into three groups: Properties that return information on the operating system, those that return information on screen settings, and those that return information about battery status. All the properties exposed by this control are read-only.
The first group includes the OSPlatform, OSVersion, and OSBuild properties. OSPlatform returns 1 if the application is being executed under Windows 95 or Windows 98, or it returns 2 if it's being executed under Windows NT. OSVersion returns the Windows version (as a Single value). OSBuild lets you distinguish among different builds of the same version.
The second group comprises these properties: WorkAreaLeft, WorkAreaTop, WorkAreaWidth, WorkAreaHeight, and ScrollBarSize. The first four properties return the position and the size (in twips) of the work area—that is, the portion of the desktop not occupied by the Windows taskbar. You can use this information to properly move and resize your forms. ScrollBarSize returns the system-defined width of vertical scrollbars: You can use this data to make your scroll bars look good at any screen resolution.
The third group includes the following properties: ACStatus (0 for batteries, 1 for AC power), BatteryFullTime (the estimated battery life), BatteryLifePercent (the estimated remaining battery life as a percentage), BatteryLifeTime (the estimated remaining battery life in seconds), and BatteryStatus (1 for High, 2 for Low, 4 for Critical, 8 for Charging). All these properties return a special value (-1 for ACStatus and BatteryStatus, 255 for the other properties) when the requested information is unknown. For more information, see the source code of the demonstration program (shown in Figure 12-11) provided on the companion CD.
Figure 12-11. The demonstration program shows how to leverage all the properties and events of the SysInfo control.
The SysInfo control exposes 18 custom events. They can be subdivided into the following four groups:
The simplest and most useful events are DisplayChanged, SysColorChanged, and TimeChanged, whose names are self-explanatory. Another interesting event is SettingChanged, which receives an integer that states which particular system setting has been modified. For example, your application can detect when the user has moved or resized the Windows taskbar in the following way:
Private Sub SysInfo1_SettingChanged(ByVal Item As Integer) Const SPI_SETWORKAREA = 47 If Item = SPI_SETWORKAREA Then Call Resize_Forms End Sub |
Apart from the simplest cases, however, taking advantage of SysInfo events requires a thorough knowledge of the Windows operating system.